<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>服务通知列表</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../../../css/mui.min.css">
		<link rel="stylesheet" href="../../../../css/global.css">
		<link rel="stylesheet" href="../../../../css/style.css">
		<link rel="stylesheet" href="../../../../css/checkbox.css"/>
		<style>
			.mui-checkbox input[type=checkbox], .mui-radio input[type=radio]{
				top: 8px;
				right: -10px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">服务通知列表</h1>
		</header>
		<div style="height: 30px;"></div>
		<div class="item_box">
			<div class="details_con" id="liebiao">
			</div>
			<div class="btn_box">
				<span class="fl">取消</span>
				<span class="fr red" id="save">确定</span>
			</div>
			<div style="height: 50px;"></div>
		</div>

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../../js/mui.min.js"></script>
		<script src="../../../../js/utils/h.js"></script>
		<script src="../../../../js/constant.js"></script>
		<script src="../../../../js/common.js"></script>
		<script src="../../../../js/utils/base64.js"></script>
		<script src="../../../../js/utils/md5.js"></script>
		<script src="../../../../js/utils/sortMap.js"></script>
		<script src="../../../../js/utils/http.js"></script>
		<script src="../../../../js/app.js"></script>
		<!-- 基础js end -->

		
		<script type="text/javascript" charset="utf-8">
			 //mui初始化
			var ServiceNoticeId
			var serviceNo
			var planId
			var state
			var stateName
			(function($, doc) {
				$.init();
				// 获取定位的经纬度
				app.showWaiting('加载中...');
				plus.geolocation.getCurrentPosition(function(p){
					app.closeWaiting();
					longitude = p.coords.longitude;
					latitude = p.coords.latitude;
				}, function(e){
					app.closeWaiting();
					app.toast("定位失败");
				}, {geocode: false});
				$.plusReady(function() {					
					var self = plus.webview.currentWebview();
					 // 获取上一个页面传过来的参数并显示到页面
					 ServiceNoticeId = self.ServiceNoticeId;
					 serviceNo = self.serviceNo;
					 planId = self.planId;
					 state = self.state;
					 // 获取服务通知类别
					 getFWList();
					 
					 // 确定按钮方法
					 h("#save").tap(function(){
						 // 获取checkbox的值
						 var ele = document.getElementsByName("checkbox1");
						 var ServiceNoticeIds = "";
						 var serviceNos = "";
						 var planIds = "";
						 for (var i = 0; i < ele.length; i++) {
							if(ele[i].checked){
								planIds += ele[i].value+",";
								ServiceNoticeIds += document.getElementById(ele[i].value).getAttribute('serviceNoticeId') + ",";
								serviceNos += document.getElementById(ele[i].value).getAttribute('serviceNo') + ",";
							}
						 }
						 // 加上之前页面传过来的参数
						 // planIds += planId;
						 // ServiceNoticeIds += ServiceNoticeId;
						 // serviceNos += serviceNo;
						 // console.log("planIds:"+planIds+"	ServiceNoticeIds:"+ServiceNoticeIds+"	serviceNos:"+serviceNos)
						 planIds = planIds.slice(0, planIds.length-1);
						 ServiceNoticeIds = ServiceNoticeIds.slice(0, ServiceNoticeIds.length-1);
						 serviceNos = serviceNos.slice(0, serviceNos.length-1);
						 if(serviceNos == ""){
						 	app.toast("请勾选服务通知");
						 	return
						 }
						
						//  ajaxGet(BASE_URL + "cc/instrument/checkAddressDistance", {
						// 	"ServiceNoticeId": ServiceNoticeId,
						// 	"longitude": longitude,
						// 	"latitude": latitude
						//  }, function(data) {
						// 	console.log(JSON.stringify(data))
						// 	if(data.code==200){
						// 		if(data.data){ //跳转地址变更页
						// 			app.jumpTo("/view/service/addressChange/addressChange.html", "/view/service/addressChange/addressChange.html",
						// 			{
						// 				serviceNos: serviceNos,
						// 				ServiceNoticeIds: ServiceNoticeIds
						// 			});
						// 		}else{ //直接签到
						// 			ajaxGet(BASE_URL + "cc/PlanDetails/fseSign", {
						// 				"ServiceNoticeIds": ServiceNoticeIds,
						// 				"serviceNos": serviceNos,
						// 				"planIds": planIds,
						// 				"EnginnerId": app.getUser().enginnerId,
						// 				"longitude": longitude,
						// 				"latitude": latitude
						// 			}, function(data) {
						// 				console.log(JSON.stringify(data))
						// 				if(data.code==200){
						// 					app.toast("保存成功")
						// 					// 查找上级页面并关闭页面
						// 					var signIn = plus.webview.getWebviewById('view/service/notice/signIn.html');
						// 					if (signIn) {
						// 						signIn.close()
						// 					}
						// 					// 查找需要跳转的页面，并指定刷新的方法
						// 					var assignList = plus.webview.getWebviewById('view/service/notice/acceptedList.html');
						// 					assignList.evalJS('getList()')
						// 					$.back()
						// 				}
						// 			}, function(errorMsg) {
						// 				app.toast(errorMsg)
						// 			});
						// 		}
						// 	}else{
						// 		 app.toast(data.msg)
						// 	}
						//  }, function(errorMsg) {
						// 	 app.toast(errorMsg)
						//  });
					 // });
				});
			}(mui, document));
			
			// 获取服务通知类别
			function getFWList(){
				ajaxGet(BASE_URL + "cc/notice/AssociatedCustomers", {
					"ServiceNoticeId": ServiceNoticeId,
					"EnginnerId": app.getUser().enginnerId,
					"state": state,
					"planId": planId
				}, function(data) {
					var html = "";
					h("#liebiao").html("");
					if(data.data && data.data.length > 0){
						for(var i=0;i<data.data.length;i++){
							var dts = data.data[i];
							var hopeBusinessHours = "";
							var isChecked = "";
							if (dts.hopeBusinessHours != undefined && dts.hopeBusinessHours != 'undefined' && dts.hopeBusinessHours !="")
							{
							    hopeBusinessHours = dts.hopeBusinessHours;
							}
							if (dts.serviceNo == serviceNo){
								isChecked = 'checked';
							}
							html += '<div class="item">'
								html += '<div class="bar">'
									html += '<span class="number">'+dts.serviceNo+'<img src="../../../images/icon_204.png" /></span>'
									html += '<div class="checkbox">'
										html += '<div class="mui-input-row mui-checkbox" id="'+dts.id+'" serviceNoticeId='+dts.serviceNoticeId+' serviceNo='+dts.serviceNo+' >'
											html += '<input name="checkbox1" value="'+dts.id+'" type="checkbox" class="rdss" '+ isChecked +'/>'
											html += '<label></label>'
										html += '</div>' 
									html += '</div>'
								html += '</div>'
								html += '<div class="name">'
									html += dts.customerName
								html += '</div>'
								html += '<div class="type">'
									html += '<p>提交时间：<span>'+dts.createTime+'</span><img src="../../../images/icon_202.png"/></p>'
									//默认0待接受，1已接受，2已签到，3已签离，4已完成,5自动签离，6已拒绝
									state = dts.state;
									if(state == '0'){
										stateName = "待接受";
									}else if(state == '1'){
										stateName = "已接受";
									}else if(state == '2'){
										stateName = "已签到";
									}else if(state == '3'){
										stateName = "已签离";
									}else if(state == '4'){
										stateName = "已完成";
									}else if(state == '5'){
										stateName = "自动签离";
									}else if(state == '6'){
										stateName = "已拒绝";
									}
									html += '<p>状态：<span>'+stateName+'</span><img src="../../../images/icon_205.png"/></p>'
									html += '<p>服务子类型：<span>' + dts.subServiceType + '<span><img src="../../../images/icon_203.png"/></p>'
									html += '<p>期望服务时间：<span>' + hopeBusinessHours + '</span><img src="../../../images/icon_202.png"/></p>'
								html += '</div>'
							html += '</div>';
						}
						h("#liebiao").html(html);
					}
				}, function(errorMsg) {
					console.log(JSON.stringify(errorMsg))
				});
			}
			
		</script>
		<!-- js代码 end -->

	</body>

</html>
